<?php
/**
 * spsNewsletter controller for subscriber managment
 * 
 * @author Satyan Shah <joomlaDesign@modernbridge.com>
 * @link http://www.modernbridge.com
 * @license GNU/GPL
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();


class spsNewslettersControllersubscriber extends spsNewslettersController
{
	/**
	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	function __construct()
	{
		parent::__construct();

		// Register Extra tasks, in this case we are saying to tread add like edit;
		$this->registerTask( 'add'  , 'edit' );

	}

	function edit()
	{  
		// the view is now (propertly) handled by the controller. The call below shoulnd't be needed
		//JRequest::setVar( 'view', 'subscriber' );
		JRequest::setVar( 'layout', 'form'  );
		JRequest::setVar('hidemainmenu', 1);
		parent::display();
	}

	// save the subscriber
	function save()
	{
		// get the model
		$model = $this->getModel('subscriber');
		// attempt to store and set user message accordingly
		if ($model->store($post)) {
			$msg = JText::_( 'spsNewsletter: Subscriber added to database' );
		} 
		else {
			$msg = JText::_( 'spsNewsletter: Error adding subscriber to database' );
		}

		// redirect
		$link = 'index.php?option=com_spsNewsletter&controller=subscriber';
		$this->setRedirect($link, $msg);
	}
	
	// delete a subscriber
	function remove()
	{
		// get the model
		$model = $this->getModel('subscriber');
		
		// attempt to delete and set user message accordingly
		if(!$model->delete()) {
			$msg = JText::_( 'Error: One or More Greetings Could not be Deleted' );
		} 
		else {
			$msg = JText::_( 'Greeting(s) Deleted' );
		}
		// redirect
		$this->setRedirect( 'index.php?option=com_spsNewsletter&controller=subscriber', $msg );
	}

	// cancel
	function cancel()
	{
		// set user message redirect
		$msg = JText::_( 'Operation Cancelled' );
		$this->setRedirect( 'index.php?option=com_spsNewsletter&controller=subscriber', $msg );
	}
}
?>
